package com.atzxh.java;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author 小红同学
 * @create 2023-04-17-23:46
 * @description
 */
// 图书管理系统
public class Copilot {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Book> books = new ArrayList<>();

        while (true) {
            System.out.println("请选择操作：");
            System.out.println("1.添加图书");
            System.out.println("2.查找图书");
            System.out.println("3.删除图书");
            System.out.println("4.显示所有图书");
            System.out.println("5.退出");

            int choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    System.out.println("请输入书名：");
                    String name = scanner.next();
                    System.out.println("请输入作者：");
                    String author = scanner.next();
                    System.out.println("请输入出版社：");
                    String publisher = scanner.next();
                    books.add(new Book(name, author, publisher));
                    System.out.println("添加成功！");
                    break;
                case 2:
                    System.out.println("请输入要查找的书名：");
                    String searchName = scanner.next();
                    for (Book book : books) {
                        if (book.getTitle().equals(searchName)) {
                            System.out.println(book);
                            break;
                        }
                    }
                    break;
                case 3:
                    System.out.println("请输入要删除的书名：");
                    String deleteName = scanner.next();
                    for (Book book : books) {
                        if (book.getTitle().equals(deleteName)) {
                            books.remove(book);
                            System.out.println("删除成功！");
                            break;
                        }
                    }
                    break;
                case 4:
                    for (Book book : books) {
                        System.out.println(book);
                    }
                    break;
                case 5:
                    System.exit(0);
                default:
                    System.out.println("输入有误，请重新输入！");
                    break;
            }
        }


    }

}



class Book {
    // 一个完整的Book类 有书名、作者、出版社三个属性,以及对应的get，set方法
      private String title;
      private String author;
      private String publisher;

    public Book() {
    }

    public Book(String title, String author, String publisher) {
        this.title = title;
        this.author = author;
        this.publisher = publisher;
    }

    public String getTitle() {
          return title;
      }
      public void setTitle(String title) {
          this.title = title;
      }
      public String getAuthor() {
          return author;
      }
      public void setAuthor(String author) {
          this.author = author;
      }
      public String getPublisher() {
          return publisher;
      }
      public void setPublisher(String publisher) {
          this.publisher = publisher;
      }







}


















